<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>用户注册</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<link rel="stylesheet" href="../css/adduser.css" type="text/css"
	media="screen" />
<link rel="stylesheet" href="../css/all.css" type="text/css"
	media="screen" />
<link rel="stylesheet" type="text/css" href="../css/style.css">
<link rel="stylesheet" type="text/css" href="../js/showDialog.css">

<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/leqi.js"></script>
<script type="text/javascript" src="../js/md5.js"></script>
    <script type="text/javascript" src="../js/showDialog.js"> </script>
<script type="text/javascript">
	var check = false;
	var email;
	$(document).ready(function() {

		addTable("../content/table.html", false, callback);

	});
	function callback() {
		var stepIndex = GetQueryString("step");
		if (stepIndex == null) {
			stepIndex = 1;
		} else {
			stepIndex = parseInt(stepIndex);
		}
		step(stepIndex);
	}
	function step(index) {

		switch (index) {
		case 1:
			stepFirst();
			break;
		case 2:

			stepSecond();
			break;
		case 3:
			stepthird();
			break;
		default:

		}
	}

	function stepFirst() {
		$.ajax({
			url : "./userinfo.html",
			dataType : "text",
			type : "POST",
			success : function(msg) {
				$("#contentList").html(msg);
			},
			error : function() {
			}
		});
	}

	function stepSecond() {

		email = GetQueryString("email");

		$("#contentList").html(
				"您的申请已提交成功，请查看您的注册<a href='mail."+email+"'>邮箱</a>。 ");

		email = GetQueryString("email");
		$.ajax({
			url : "./findPasswordSended.html",
			dataType : "text",
			type : "POST",
			success : function(msg) {
				$("#contentList").html(msg);
				emailLoad();
			},
			error : function() {
			}
		});

	}

	function emailLoad() {
		$("#emailloaded").attr("href", "http://mail." + email);

	}

	function stepthird() {
		var uuid = GetQueryString("code");

		$
				.ajax({
					url : httpURL
							+ "/user/user_checkUserByUuid!checkUserByUuid.do?activityCode="
							+ uuid,
					dataType : "json",
					type : "POST",
					success : function(msg) {
						if (msg.msg == "ok") {
							addstep3();
						} else {
							alert("激活失败");
						}

					},
					error : function() {
					}
				});

	}

	function addstep3() {
		$.ajax({
			url : "./changePassword.html",
			dataType : "text",
			type : "POST",
			success : function(msg) {
				$("#contentList").html(msg);
			},
			error : function() {
			}
		});
	}

	function findPassword() {

		var email = $('#email').val();
		checkYanZheng();
		if (check) {
			var dataStr = "email=" + email;
			$
					.ajax({
						url : "http://localhost:8080/user/user_findPassword!findPassword.do",
						data : dataStr,
						type : "POST",
						dataType : "json",
						success : function(result) {
							if (result.msg == 'ok') {
								window.location.href = httpURL
										+ "/user/findPassword.html?step=2&email="
										+ result.mail;
							} else {
								alert("注册失败！！");
							}
						}
					});
		} else {
			alert("输入不正确！！");
		}

		// alert(username+"::"+password+"::"+email);
	}

	function changePassword() {
		var password = $("#password").val();
		var repassword = $("#repassword").val();

		if (password != repassword) {
			alert("两次输入的密码不相同");
			loadimage();
			return;
		}

		// var code =  $("#code").val();
		var uuid = GetQueryString("code");
		checkYanZheng();
		password = hex_md5(password);
		var dataStr = "password=" + password + "&activityCode=" + uuid;
		$
				.ajax({
					url : httpURL+"/user/user_modifyPassword!modifyPassword.do",
					data : dataStr,
					type : "POST",
					dataType : "json",
					success : function(result) {
						if (result.msg == 'ok') {
							alert("修改成功");
							loginUserNameAndPassword(result.username,password);
							window.location.href = httpURL;

						} else {
							alert("修改失败！！");
						}

						$("#password").val("");
						$("#repassword").val("");
						
					}
				});
	}

	function checkUser(username) {
		if (username == '') {
			$('#usernamemessage').html("用户名不能为空!!").addClass("error");
			addClass($('#username'), "resister-input-error");
			check = false;

		} else {
			$('#usernamemessage').html("ok!!").addClass("right");
			removeClass($('#username'), "resister-input-error");
			check = true;
		}
	}

	function checkPass(password) {
		var repassword = $('#repassword').val();
		//var password = $('#password').val();
		if (password == '') {
			$('#passwordmessage').html("没有输入密码").addClass("error");
			checked = false;
			addClass($('#password'), "resister-input-error");
		} else {
			$('#passwordmessage').html("ok").addClass("right");
			checked = true;
			removeClass($('#password'), "resister-input-error");
			addClass($('#password'), "resister-input");
		}

		if (repassword != "") {
			if (password != repassword) {
				removeClass($('#passwordmessage'), "right");
				$('#passwordmessage').html("两次输入的密码不相同").addClass("error");

				addClass($('#password'), "resister-input-error");
				checked = false;
			} else {
				checkTwoPasswordOk();
			}
		}
	}

	function checkTwoPasswordOk() {
		checked = true;
		removeClass($('#repassword'), "resister-input-error");
		removeClass($('#password'), "resister-input-error");
		//	addClass($('#repassword'), "resister-input");
		//addClass($('#password'), "resister-input");
		$('#passwordmessage').html("ok").addClass("right");
		$('#repasswordmessage').html("ok").addClass("right");
	}

	function checkRepass(repassword) {
		//var repassword = $('#repassword').val();
		var password = $('#password').val();
		if (repassword == '') {
			$('#repasswordmessage').html("没有输入密码").addClass("error");
			checked = false;
			addClass($('#repassword'), "resister-input-error");
		}
		if (password != repassword) {
			removeClass($('#repasswordmessage'), "right");
			$('#repasswordmessage').html("两次输入的密码不相同").addClass("error");
			checked = false;
			addClass($('#repassword'), "resister-input-error");
		} else {
			checkTwoPasswordOk();
		}
	}

	function removeClass(node, cla) {
		node.removeClass(cla);
	}
	function addClass(node, cla) {
		node.addClass(cla);
	}

	function loadimage() {
		var timenow = new Date().getTime();
		$("#yanzheng").attr("src",
				"http://localhost:8080/servlet/ImageServlet?d=" + timenow);
		return false;
	}

	function checkYanZheng() {
		var code = $("#code").val();

		$
				.ajax({
					url : "http://localhost:8080/edit/content!checkYanZhengMa.do",
					type : 'post',
					dataType : "json",
					async : false,
					success : function(msg) {

						if (code.toLocaleLowerCase() != msg.piccode
								.toLocaleLowerCase()) {
							alert(code + "验证码不对" + msg.piccode);
						}
					}
				});

	}
</script>
<style type="text/css">
.error {
	color: red;
}

.right {
	color: green;
}
</style>
</head>

<body class="allback">

</body>
</html>
